<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" lang="zh" class="no-js">
<head th:include="common_include :: commonHead('用户管理')"/>
<link th:href="@{/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 组织机构
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开"><i
                            class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠" style="display:none;"><i
                            class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新机构"><i
                            class="fa fa-refresh"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnEraser" title="清除条件"><i
                            class="fa fa-eraser"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
</div>
<div class="ui-layout-center wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>用户管理</h5>
                </div>
                <div class="ibox-content">
                    <div class="row row-lg">
                        <div class="col-sm-12">
                            <div class="row">
                                <form id="query-form">
                                    <input type="hidden" name="deptid" id="deptid"/>
                                    <div class="col-sm-5">
                                        <div class="input-group m-b">
                                            <span class="input-group-addon">用户名称</span>
                                            <input type="text" name="userName" id="userName"
                                                   class="form-control" placeholder="用户名称">
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                                class="fa fa-search"></i>&nbsp;搜索</a>
                                    </div>
                                </form>
                            </div>
                            <div class="btn-group hidden-xs" id="toolbar" user="group">
                                <a class="btn btn-outline btn-success btn-rounded"
                                   shiro:hasPermission="upms:user:add" onclick="$.operate.add(0)"><i
                                        class="fa fa-plus"></i> 新增</a>
                                <a class="btn btn-outline btn-danger btn-rounded"
                                   shiro:hasPermission="upms:user:delete" onclick="$.operate.batRemove()"><i
                                        class="fa fa-trash-o"></i> 删除</a>
                            </div>
                            <div class="col-sm-12 select-info table-striped">
                                <table id="bootstrap-table" data-mobile-responsive="true"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="common_include :: commonFoot"/>
<script th:src="@{/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.displayWithPermission('upms:user:edit')}]];
    var deleteFlag = [[${@permission.displayWithPermission('upms:user:delete')}]];
    var passwordFlag = [[${@permission.displayWithPermission('upms:user:password')}]];
    var dicts = [[${@dictCode.selectDictCodeByType('sys_user_status')}]];
    var prefix = ctx + "upms/user";
    $(function () {
        $('body').layout({west__size: 200});
        // 树结构初始化加载
        var setting = {
            view: {selectedMulti: false}, data: {key: {title: "title"}, simpleData: {enable: true}},
            callback: {
                onClick: function (event, treeId, treeNode) {
                    $("#deptid").val(treeNode.id);
                    $.table.search();
                }
            }
        }, tree, loadTree = function () {
            $.get(ctx + "upms/dept/deptTreeData", function (data) {
                tree = $.fn.zTree.init($("#tree"), setting, data);
            }, null, null, "正在加载，请稍后...");
        };
        loadTree();

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/delete",
            exportUrl: prefix + "/export",
            modalName: "用户",
            search: false,
            showExport: false,
            columns: [{
                checkbox: true
            }, {
                field: 'rowKey',
                title: '主键ID',
                sortable: true,
                visible: false
            }, {
                field: 'userAccount',
                title: '账号',
                sortable: true
            }, {
                field: 'userName',
                title: '名称',
                sortable: true
            }, {
                field: 'deptName',
                title: '归属部门'
            }, {
                field: 'phone',
                title: '联系电话',
                sortable: true
            }, {
                field: 'email',
                title: '电子邮箱',
                sortable: true
            }, {
                field: 'userStatus',
                title: '用户状态',
                align: 'center',
                formatter: function (value, row, index) {
                    return $.table.selectDictName(dicts, value);
                }
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.rowKey + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + deleteFlag + '" href="#" onclick="$.operate.remove(\'' + row.rowKey + '\')"><i class="fa fa-remove"></i>删除</a> ');
                    actions.push('<a class="btn btn-info btn-xs ' + passwordFlag + '" href="#" onclick="updatePassword(\'' + row.rowKey + '\')"><i class="fa fa-key"></i>重置</a> ');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);

        $('#btnExpand').click(function() {
            tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });
        $('#btnCollapse').click(function() {
            tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });
        $('#btnRefresh').click(function() {
            loadTree();
        });
        $('#btnEraser').click(function() {
            $("#deptid").val("");
            $.table.search();
        });
    });

    /*用户管理-重置密码*/
    function updatePassword(userId) {
        var url = prefix + '/updatePassword/' + userId;
        $.modal.open("重置密码", url, '800', '400');
    }
</script>
</html>